package calc.equations;
import java.util.Map;
import java.util.HashMap;
import java.util.Random;

public class SubtractionEquation implements Equation {

	Map<Integer, String> templates;
	int templateCount;
	
	public SubtractionEquation(){
		templates = new HashMap<Integer, String>();
		templateCount = 0;
		add(getChar() + " - " + getChar());
	}
	
	public SubtractionEquation(String otherEquation){
		templates = new HashMap<Integer, String>();
		templateCount = 0;
		add(getChar() + " - " + otherEquation);
		add("(" + otherEquation + ") - " + getChar());
		add(getChar() + " - (" + otherEquation + ")");
	}
	
	public SubtractionEquation(Equation equ){
		templates = new HashMap<Integer, String>();
		templateCount = 0;
		add(getChar() + " - " + equ.getRandomTemplate());
		add("(" + equ.getRandomTemplate() + ") - " + getChar());
		add(getChar() + " - (" + equ.getRandomTemplate() + ")");
	}
	
	public void add(String template){
		templates.put(templateCount, template);
		templateCount++;
	}
	
	public int numberOfTemplates() {
		return templateCount;
	}

	public int equationID() {
		return 1;
	}

	public String getTemplate(int key) {
		if(templates.containsKey(key)){
			return templates.get(key);
		}else{
			return null;
		}
	}

	public String getRandomTemplate() {
		Random randomGenerator = new Random();	
		return templates.get(randomGenerator.nextInt(templateCount));
	}
	
	public char getChar(){
		Random random = new Random();
		return (char) (random.nextInt(26) + 'a');
	}
}
